package site.xuxingcan.autologin;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

/**
 * Created by xuxingcan on 2016/9/8.
 */
public class UserActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.user_layout);
        ((EditText) findViewById(R.id.lianzong_user)).setText(SharedPreferenceUtil.getInstance().getLianZongUser());
        ((EditText) findViewById(R.id.lianzong_pwd)).setText(SharedPreferenceUtil.getInstance().getLianZongPwd());
        ((EditText) findViewById(R.id.yunma_user)).setText(SharedPreferenceUtil.getInstance().getYunmaUser());
        ((EditText) findViewById(R.id.yunma_pwd)).setText(SharedPreferenceUtil.getInstance().getYunmaPwd());
        findViewById(R.id.lianzong_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String user = ((EditText) findViewById(R.id.lianzong_user)).getText().toString().trim();
                String pwd = ((EditText) findViewById(R.id.lianzong_pwd)).getText().toString().trim();
                if (TextUtils.isEmpty(user) || TextUtils.isEmpty(pwd)) {
                    Toast.makeText(UserActivity.this, "账号密码不能为空！", Toast.LENGTH_LONG).show();
                    return;
                }
                SharedPreferenceUtil.getInstance().setLianZongUser(user);
                SharedPreferenceUtil.getInstance().setLianZongPwd(pwd);
                Toast.makeText(UserActivity.this, "设置成功！", Toast.LENGTH_LONG).show();
            }
        });
        findViewById(R.id.yunma_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String user = ((EditText) findViewById(R.id.yunma_user)).getText().toString().trim();
                String pwd = ((EditText) findViewById(R.id.yunma_pwd)).getText().toString().trim();
                if (TextUtils.isEmpty(user) || TextUtils.isEmpty(pwd)) {
                    Toast.makeText(UserActivity.this, "账号密码不能为空！", Toast.LENGTH_LONG).show();
                    return;
                }
                SharedPreferenceUtil.getInstance().setYunmaUser(user);
                SharedPreferenceUtil.getInstance().setYunmaPwd(pwd);
                Toast.makeText(UserActivity.this, "设置成功！", Toast.LENGTH_LONG).show();
            }
        });
    }
}
